package com.zh.springcloud;

import lombok.Data;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description:
 * @ClassName PaymentApplication
 * @date: 2021.07.06 09:23
 * @Author: zhanghang
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class PaymentApplication {

	@Test
	public void test_01(){
		List<Object> list = new ArrayList<>();

		ExecutorService pool = Executors.newFixedThreadPool(4);
		pool.execute(() -> {
			System.out.println(Thread.currentThread().getName()+"===");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

		pool.execute(() -> {
			System.out.println(Thread.currentThread().getName()+"+++");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		System.out.println("==============");
	}

	@Test
	public void test02(){
		String str = "varchar(68)";
		String i = "tinyint(4)";

		System.out.println(str.substring(8,str.length()));
	}

	@Data
	static class Apple {
		private Integer id;
		private String name;
		private BigDecimal money;
		private Integer num;
		public Apple(Integer id, String name, BigDecimal money, Integer num) {
			this.id = id;
			this.name = name;
			this.money = money;
			this.num = num;
		}
	}

	@Test
	public void test03(){
		ExecutorService executorService = Executors.newFixedThreadPool(10);
		List<Future> list = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			int finalI = i;
			Future<?> submit = executorService.submit(() -> {
				try {
					pringlnStr(finalI);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			});
			list.add(submit);
		}
		for (Future future : list) {
			try {
				future.get();
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		}
		System.out.println("*****************");
	}

	private void pringlnStr(int i) throws InterruptedException {
		TimeUnit.SECONDS.sleep(1);
		System.out.println(Thread.currentThread().getName()+"========"+i);
	}
}
